package com.qys.livesMall.anchor.controller.sys;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.anchor.model.dto.task.sys.SysSellLivesAnchorPageDTO;
import com.qys.livesMall.anchor.model.vo.task.sys.SysSellLivesAnchorPageVO;
import com.qys.livesMall.anchor.service.AnchorSellLivesApplyService;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.common.utils.MessageUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 主播直播带货申请表 前端控制器
 * </p>
 *
 * @author wzy
 * @since 2023-06-20
 */
@RestController
@Tag(name = "后台管理-主播直播带货")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/sys/anchor/sell/lives")
public class SysAnchorSellLivesController {


    private final AnchorSellLivesApplyService anchorSellLivesApplyService;


    @PostMapping("/anchorSellLivesApplyList")
    @Operation(summary = "分页查询主播直播申请列表")
    public R<Page<SysSellLivesAnchorPageVO>> anchorSellLivesApplyList(@RequestBody SysSellLivesAnchorPageDTO queryDTO) {
        return R.ok(anchorSellLivesApplyService.pageBySys(queryDTO));
    }

    @GetMapping("/livesApplyDetail/{id}")
    @Operation(summary = "主播直播申请详情",parameters = {@Parameter(name = "id", description = "直播申请id")})
    public R<SysSellLivesAnchorPageVO> livesApplyDetail(@PathVariable Long id) {
        return R.ok(anchorSellLivesApplyService.sysDetail(id));
    }


    @PutMapping("/pass/{id}")
    @Operation(summary = "主播直播申请通过审核", parameters = {@Parameter(name = "id", description = "直播申请id")})
    public R<?> pass(@PathVariable Long id) {
        if (anchorSellLivesApplyService.pass(id)==1){
            return R.fail(MessageUtils.message("审核时间已超过申请开播时间,已拒绝通过"));
        }
        return R.ok();
    }


    @PutMapping("/noPass/{id}")
    @Operation(summary = "主播直播申请未通过审核", parameters = {@Parameter(name = "id", description = "直播申请id")})
    public R<Void> noPass(@PathVariable Long id) {
        anchorSellLivesApplyService.noPass(id);
        return R.ok();
    }


}
